package com.xinchuang.mapper.targetSystem.icon;

import com.xinchuang.entity.targetSystem.icon.IconData;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @ClassName IconDataMapper
 * @Description: TODO(写一段描述的话)
 * @Author zhangxuan
 * @Date 2022-08-23 15:48
 * @Verion V1.0
 */
@Repository
public interface IconDataMapper {

    @Insert(value = {
            "INSERT INTO icon_table (id,icon_url,type,remark) VALUES (#{id},#{iconUrl},#{type},#{remark})"
    })
    int addIconData(IconData iconData);

    @Update(value = {
            "<script>",
            "UPDATE icon_table ",
            "<set>",
            "<if test = 'iconUrl != null'>icon_url = #{iconUrl},</if>",
            "<if test = 'type != null'>type = #{type},</if>",
            "<if test = 'remark != null'>remark = #{remark},</if>",
            "</set>",
            "WHERE id = #{id}",
            "</script>"
    })
    int updateIconData(IconData iconData);

    @Delete(value = "DELETE FROM icon_table WHERE id = #{id}")
    int delIconData(String id);

    @Select(value = {
            "SELECT id,icon_url,type,remark FROM icon_table WHERE type = #{type}"
    })
    @Results(
            value = {
                    @Result(property = "iconUrl", column = "icon_url")
            }
    )
    List<IconData> selectIconDataList(int type);

    @Select(value = {
            "SELECT id AS value,icon_url AS label FROM icon_table WHERE type = #{type}"
    })
    List<Map<String, Object>> selectIconDataPull(int type);

    @Select(value = "SELECT icon_url FROM icon_table WHERE id = #{id}")
    String selectIconUrlById(String id);

}